package com.jb.repair.util;

import android.content.Context;
import android.content.Intent;
import android.widget.Toast;

import com.jb.repair.common.MyIntent;

/**
 * Created by SLF on 2016/1/6.
 */
public class IntentUtils {
    public static void JumpToIntent(Context context, String fjlx, String filePath) {

        if ("doc".equals(fjlx) || "docx".equals(fjlx)) {
            Intent intent = MyIntent.getWordFileIntent(filePath);
            if (MyIntent.isIntentAvailable(context, intent)) {
                context.startActivity(intent);
            } else {
                Toast.makeText(context, "未安装此类应用", Toast.LENGTH_SHORT).show();
            }
        } else if ("pdf".equals(fjlx)) {
            Intent intent = MyIntent.getPdfFileIntent(filePath);
            if (MyIntent.isIntentAvailable(context, intent)) {
                context.startActivity(intent);
            } else {
                Toast.makeText(context, "未安装此类应用", Toast.LENGTH_SHORT).show();
            }
        } else if ("tif".equals(fjlx) || "jpg".equals(fjlx) || "gif".equals(fjlx) || "png".equals(fjlx) || "log".equals(fjlx) || "bak".equals(fjlx) || "bmp".equals(fjlx)) {
            Intent intent = MyIntent.getImageFileIntent(filePath);
            if (MyIntent.isIntentAvailable(context, intent)) {
                context.startActivity(intent);
            } else {
                Toast.makeText(context, "未安装此类应用", Toast.LENGTH_SHORT).show();
            }
        } else if ("dwg".equals(fjlx)) {
            Intent intent = MyIntent.getImageFileIntent(filePath);
            if (MyIntent.isIntentAvailable(context, intent)) {
                context.startActivity(intent);
            } else {
                Toast.makeText(context, "未安装此类应用", Toast.LENGTH_SHORT).show();
            }
        } else if ("log".equals(fjlx) || "txt".equals(fjlx) || "xml".equals(fjlx) || "cpp".equals(fjlx)) {
            Intent intent = MyIntent.getTextFileIntent(filePath);
            if (MyIntent.isIntentAvailable(context, intent)) {
                context.startActivity(intent);
            } else {
                Toast.makeText(context, "未安装此类应用", Toast.LENGTH_SHORT).show();
            }
        } else if ("xls".equals(fjlx) || "xlsx".equals(fjlx)) {
            Intent intent = MyIntent.getExcelFileIntent(filePath);
            if (MyIntent.isIntentAvailable(context, intent)) {
                context.startActivity(intent);
            } else {
                Toast.makeText(context, "未安装此类应用", Toast.LENGTH_SHORT).show();
            }

        } else if ("ppt".equals(fjlx) || "pptx".equals(fjlx)) {
            Intent intent = MyIntent.getPptFileIntent(filePath);
            if (MyIntent.isIntentAvailable(context, intent)) {
                context.startActivity(intent);
            } else {
                Toast.makeText(context, "未安装此类应用", Toast.LENGTH_SHORT).show();
            }
        } else if ("html".equals(fjlx) || "php".equals(fjlx) || "jsp".equals(fjlx) || "htm".equals(fjlx)) {
            Intent intent = MyIntent.getHtmlFileIntent(filePath);
            if (MyIntent.isIntentAvailable(context, intent)) {
                context.startActivity(intent);
            } else {
                Toast.makeText(context, "未安装此类应用", Toast.LENGTH_SHORT).show();
            }
        } else if ("mp3".equals(fjlx) || "wav".equals(fjlx) || "ogg".equals(fjlx) || "midi".equals(fjlx)) {
            Intent intent = MyIntent.getAudioFileIntent(filePath);
            if (MyIntent.isIntentAvailable(context, intent)) {
                context.startActivity(intent);
            } else {
                Toast.makeText(context, "未安装此类应用", Toast.LENGTH_SHORT).show();
            }
        } else if ("mp4".equals(fjlx) || "rmvb".equals(fjlx) || "avi".equals(fjlx) || "flv".equals(fjlx)) {
            Intent intent = MyIntent.getAudioFileIntent(filePath);
            if (MyIntent.isIntentAvailable(context, intent)) {
                context.startActivity(intent);
            } else {
                Toast.makeText(context, "未安装此类应用", Toast.LENGTH_SHORT).show();
            }
        } else if ("apk".equals(fjlx) || "zip".equals(fjlx) || "jar".equals(fjlx) || "rar".equals(fjlx)|| "jar".equals(fjlx) || "gz".equals(fjlx)) {
            Intent intent = MyIntent.getAudioFileIntent(filePath);
            if (MyIntent.isIntentAvailable(context, intent)) {
                context.startActivity(intent);
            } else {
                Toast.makeText(context, "未安装此类应用", Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(context, "未知文件类型", Toast.LENGTH_SHORT).show();
        }
    }
}